package com.ruoyi.web.controller.trade;

import com.github.pagehelper.PageInfo;
import com.hundun.vision.api.dto.CriterionDTO;
import com.hundun.vision.api.dto.RobotDTO;
import com.hundun.vision.api.query.BackTestQuery;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.BucketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：RuoChen
 * @date ：20:24 2021/3/2
 * @description：回测控制器
 */
@RestController
@RequestMapping("/trade/bucket")
public class BucketController extends BaseController {

    @Autowired
    private BucketService bucketService;

    @PreAuthorize("@ss.hasPermi('trade:bucket:get')")
    @GetMapping("/get")
    public AjaxResult get() {
        AjaxResult ajax = AjaxResult.success();
        List<RobotDTO> robots = bucketService.getRobots();
        ajax.put("robots", robots);
        return ajax;
    }

    @PreAuthorize("@ss.hasPermi('trade:bucket:test')")
    @GetMapping(value = "/test")
    public AjaxResult test(BackTestQuery query) {
        AjaxResult ajax = AjaxResult.success();
        bucketService.test(query);
        return ajax;
    }

    @PreAuthorize("@ss.hasPermi('trade:bucket:search')")
    @GetMapping("/search")
    public TableDataInfo search(BackTestQuery query) {
        PageInfo<CriterionDTO> pageInfo = bucketService.search(query);
        return getDataTable(pageInfo);
    }
}
